package seeders

import (
	"fmt"

	"gorm.io/gorm"

	"github.com/runningwater/gohub/database/factories"
	"github.com/runningwater/gohub/pkg/console"
	"github.com/runningwater/gohub/pkg/logger"
	"github.com/runningwater/gohub/pkg/seed"
)

func init() {
	// 添加 Seeder
	seed.Add("TopicsTableSeeder", func(db *gorm.DB) {
		// 创建 10 个用户对象
		topics := factories.MakeTopics(10)

		// 批量插入到数据库
		result := db.Table("topics").Create(&topics)

		if err := result.Error; err != nil {
			logger.LogIf(err)
			return
		}

		// 打印成功信息
		console.Success(fmt.Sprintf("Table [%v] %v rows seeded", result.Statement.Table, result.RowsAffected))
	})
}
